import service from "../axios/axios";
import Function from "../utils/function";
import de from "element-ui/src/locale/lang/de";

const {isInVue} = Function;

export default {
  //school
  getSchool() {
    return new Promise((resolve, reject) => {
      service.get("/sys/sysOrganize/getSchool").then(res => {
        resolve(res)
      });
    })
  },
  //subject
  getAllSubList() {
    return new Promise((resolve, reject) => {
      service.get("/sys/courseware/getAllSubList").then(resolve);
    });
  },
  getSubjects() {
    return new Promise((resolve, reject) => {
      service.get("/sys/subject/getSysSubject").then(res => {
        isInVue.apply(this) ? (this.subjects = res) : resolve(res);
      });
    });
  },
  getSubjectsOfQueBank(queankIdList) {
    return new Promise((resolve, reject) => {
      service
        .get("/sys/studentOnlinePractice/getSubject", {
          params: {queankIdList}
        })
        .then(res => {
          isInVue.apply(this) ? (this.subjects = res) : resolve(res);
        });
    });
  },
  //question
  getUserQueBank() {
    //查询登录用户和admin创建的题库
    return new Promise((resolve, reject) => {
      service.get("/sys/queBank/getQuestionBankSel").then(res => {
        isInVue.apply(this) ? (this.queBanks = res) : resolve(res);
      });
    });
  },
  getQueDetail(queid) {
    return new Promise((resolve, reject) => {
      service.get(`/sys/question/getQueDetail/${queid}`).then(resolve);
    });
  },
  //chapter
  getChapter(subId) {
    if (!subId) return [];
    return new Promise((resolve, reject) => {
      service.get(`/sys/courseware/getChapterBySubId/${subId}`).then(res => {
        isInVue.apply(this) ? (this.chapters = res) : resolve(res);
      });
    });
  },
  //groupChapter
  getGroupChapter(subId) {
    if (!subId) return [];
    return new Promise((resolve, reject) => {
      service.get(`/sys/chapter/getChapterBySubId/${subId}`).then(res => {
        isInVue.apply(this) ? (this.chapters = res) : resolve(res);
      });
    });
  },
  //resource
  getResource(resourceId) {
    return new Promise((resolve, reject) => {
      service.get(`/sys/courseware/getView/${resourceId}`).then(resolve);
    });
  },
  //department
  getDeptOfUser() {
    return new Promise((resolve, reject) => {
      service.get(`/sys/class/getDepartmentList`).then(resolve);
    });
  },
  getClassOfDept(deptId) {
    return new Promise((resolve, reject) => {
      service
        .get(`/sys/class/getDepartmentsClassByLogin/${deptId}`)
        .then(resolve);
    });
  },
  //class
  getStuOfClass() {
    return new Promise((resolve, reject) => {
      service.get(`/sys/examManage/getStudentByInfo`).then(resolve);
    });
  },
  //paper
  getPaperList(papertype, papername = null) {
    return new Promise((resolve, reject) => {
      service
        .get("/sys/examManage/getPaperList", {
          params: {papertype, papername}
        })
        .then(resolve);
    });
  },
  getPaperById(paperid) {
    return new Promise((resolve, reject) => {
      service
        .get(`/sys/papermanage/getUpdateData/${paperid}`)
        .then(res => resolve(res[0]));
    });
  },
  //exam
  getExaminationById(examid) {
    return new Promise((resolve, reject) => {
      service
        .post("/sys/examManage/getExamManageList", {
          examid
        })
        .then(res => {
          resolve(res.list[0]);
        });
    });
  },
  //news
  getNewsById(noticeId) {
    return new Promise((resolve, reject) => {
      service
        .get("/sys/notice/detail", {
          params: {
            noticeId
          }
        })
        .then(resolve);
    });
  }
};
